package Chuong07;

import java.io.*;
public class Bai12 {

	private static FileWriter fW;
	private static BufferedWriter bW;
	String filename = "D:/Hoc Tap/Hoc Ki VII/Chuyen De Java/OnTap_Code/OnTap/src/Chuong07/File/Fibonaci.dat";
	//String filename = "Z:/Fibonaci.dat";
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));	
	
	public Bai12(){
		try{
			fW = new FileWriter(filename);
			bW = new BufferedWriter(fW);
			System.out.print("Nhập n = ");
			int n = Integer.parseInt(in.readLine());
			if(n >= 2){
				int j = 2;
				String line = "0+1";
				if(n > 2){
					int last = 0, next = 1, temp = 2;
					do{
						j++;
						temp = last + next;	
						last = next;
						next = temp;
						line += "+" + temp;
						System.out.println(line);
						if(last + next	 > n) break;						
					}while(temp <= n);
				}
				bW.write(j + "");
				bW.newLine();
				bW.write(line);
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try { 
			bW.close();
			fW.close(); 
		} 
		catch (IOException e) { 
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Bai12();
	}

}
